package com.Master.controller;

import com.Master.domain.Master.DTO.MasterDTO;
import com.Master.domain.Master.DTO.MasterRegDTO;
import com.Master.domain.Master.MasterInfo;
import com.Master.service.Master.MasterService;
import com.common.redis.service.RedisService;
import com.comon.core.domain.result.R;
import com.comon.core.utils.ImageUtil;
import com.comon.core.utils.PasswordUtil;
import jakarta.servlet.ServletOutputStream;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.ByteArrayInputStream;
import java.io.IOException;

/**
 * Created with Intellij IDEA.
 * Description;
 * User:TQ02
 * Data:2024-08-24
 * Time:15:21
 * Text：
 */
@RestController
public class MasterController {
    @Autowired
    private MasterService service;
    @Autowired
    private ImageUtil imageUtil;
    @Autowired
    private PasswordUtil passwordUtil;
    @Autowired
    RedisService redisService;

    @PostMapping("/login")
    public R<?> login(@RequestBody MasterDTO masterDTO, HttpServletRequest request){
        System.out.println(request.getSession().getId());

        String msg = request.getSession().getAttribute("verifyCode").toString();
        boolean t = passwordUtil.decrypt(masterDTO.getCaptcha(), msg);
        if(t){
            return service.login(masterDTO);
        }
            return R.fail("验证码错误");
    }



    @PostMapping("reg")
    public R<?> reg(@RequestBody MasterRegDTO regInfo){
        return service.reg(regInfo);
    }
}
